/**
 * @author Mr
 *
 */
package com.cz.nongyetongv5.custom.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.utils.CharsetUtil;

@SuppressLint("NewApi")
public class CheckDialog extends Dialog {

	// 上下文对象
	private Context context = null;

	// 布局管理器
	private LayoutInflater inflater = null;

	// 屏幕尺度对象
	private Display display = null;

	// 确定的文本
	private String actionTxt = null;

	// 取消的文本
	private String cancleTxt = null;

	// 确定单机的时候的事件
	private android.view.View.OnClickListener onActionClickListener;

	// 取消单机的时候的事件
	private android.view.View.OnClickListener onCancleClickListener;

	// 根View
	private View root = null;

	// 底部布局
	private ViewGroup bottomBar = null;

	/**
	 * 内容布局
	 */
	private LinearLayout contentLayout = null;

	// 消息
	private String message = null;

	private TextView tvMessage = null;

	// 标题
	private String title = null;



	/**
	 * 宽度的百分比
	 */
	private float heightPercent = 0.3F;

	// 宽度比
	private float widthPercent = 0.8F;

	private String note = "";

	private TextView tvNote = null;


	public CheckDialog(Context context) {

		super(context, R.style.MyDialog);

		this.context = context;

		inflater = LayoutInflater.from(context);

		// 获得显示对象
		display = getWindow().getWindowManager().getDefaultDisplay();

		// 加载根布局
		root = inflater.inflate(R.layout.dialog_check, null);

		setContentView(root);

		setCanceledOnTouchOutside(false);

		// 加载底部布局
		//bottomBar = (ViewGroup) root.findViewById(R.id.llBottomBar);

		tvMessage = (TextView) root.findViewById(R.id.msg);

		onCancleClickListener=new android.view.View.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dismiss();
			}
		};
		root.findViewById(R.id.btn_back).setOnClickListener(onCancleClickListener);


		// 清空所有的视图
		//bottomBar.removeAllViews();

		// 查询出内容布局
		//contentLayout = (LinearLayout) findViewById(R.id.llDialogContentLayout);

		//tvNote = (TextView) root.findViewById(R.id.tvNote);
	}

	public void setSingleListener(android.view.View.OnClickListener Lis){

		root.findViewById(R.id.btn_back).setOnClickListener(Lis);
	}
	public void setSingle(String label){
		TextView t=(TextView)root.findViewById(R.id.btn_back);
		t.setText(label);
		root.findViewById(R.id.btn_ok).setVisibility(View.GONE);
		root.findViewById(R.id.line).setVisibility(View.GONE);

	}
	@Override
	public void setTitle(CharSequence title) {

		if (CharsetUtil.isNotNull((String) title)) {



		} else {

		}

	}

	@Override
	public void show() {
		super.show();

		android.view.WindowManager.LayoutParams params = getWindow()
				.getAttributes();

		// params.width = (int) ((display.getWidth() ) * widthPercent);
		params.width = LayoutParams.WRAP_CONTENT;

		params.height = (int) (display.getHeight() * heightPercent);

		getWindow().setAttributes(params);

	}


	@Override
	public void onBackPressed() {
	}

	public void setView(View view) {

		contentLayout.removeAllViews();

		contentLayout.addView(view, 0, new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	}



	public void setOnActionClickListener(
			android.view.View.OnClickListener onActionClickListener) {
		root.findViewById(R.id.btn_ok).setOnClickListener(onActionClickListener);

	}

	public void setOnCancleClickListener(
			android.view.View.OnClickListener onCancleClickListener) {
		this.onCancleClickListener = onCancleClickListener;
	}

	// 设置消息
	public void setMessage(String message) {
		this.message = message;

		if (tvMessage != null) {
			tvMessage.setText(this.message);
		}

	}

	// 设置高度的百分比
	public void setHeightPercent(float heightPercent) {
		this.heightPercent = heightPercent;
	}

	// 设置宽度百分比
	public void setWidthPercent(float widthPercent) {
		this.widthPercent = widthPercent;
	}

	public String getActionTxt() {
		return actionTxt;
	}

	public void setNote(String note) {

		this.note = note;
	}
}